import tensorflow as tf

i = tf.constant(0)
while_condition = lambda i: tf.less(i, 5)
# outs = []
def body(i):
    # do something here which you want to do in your loop
    # increment i

    return [tf.add(i, 1)]

# do the loop:
r = tf.while_loop(while_condition, body, [i])

with tf.Session() as sess:
    r_,i_,o1 = sess.run([r,i,outs[0]])
    print(r_,i_,o1)